import libsRoutes from './modules/libsRoutes'
import cssDemosRoutes from './modules/cssDemosRoutes'
import jsDemosRoutes from './modules/jsDemosRoutes'
import utilDemosRoutes from './modules/utilDemosRoutes'

import type { RouteRecordRaw } from 'vue-router'

// 根路由的重定向name(*必须是name, 因为该属性还用于左侧菜单的首次定位)
export const defaultRoute = 'CodeNote'

export default [
  {
    path: '/',
    name: 'home',
    redirect: defaultRoute,
    meta: {
      null: true
    }
  },
  ...libsRoutes,
  ...jsDemosRoutes,
  ...cssDemosRoutes,
  ...utilDemosRoutes,
] as RouteRecordRaw[]

// =======================================================================================================

const filterMenuRoutes = (routes: RouteRecordRaw[]) => {
  return routes.map((item: RouteRecordRaw) => {
    const json: RouteRecordRaw = { ...item }
    Reflect.deleteProperty(json, 'component')

    if (json.children && json.children.length) {
      json.children = filterMenuRoutes(json.children)
    } else {
      Reflect.deleteProperty(json, 'children')
    }

    return json
  })
}

export const routes_libs = filterMenuRoutes(libsRoutes)
export const routes_cssDemos = filterMenuRoutes(cssDemosRoutes)
export const routes_jsDemos = filterMenuRoutes(jsDemosRoutes)
export const routes_utilDemos = filterMenuRoutes(utilDemosRoutes)